package com.atguigu.tingshu.payment.api;

import com.atguigu.tingshu.common.login.AuthLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.payment.service.WxPayService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.service.OperationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "微信支付接口")
@RestController
@RequestMapping("api/payment")
@Slf4j
public class WxPayApiController {

    @Autowired
    private WxPayService wxPayService;


    /**
     * 支付方式为微信支付时,创建小程序拉起微信接口所需参数map
     *
     * @param paymentType 支付类型: 1301订单 1302余额充值
     * @param orderNo
     * @return {"timeStamp":"","package":"","paySign":"","signType":"RSA","nonceStr":""}
     */
    @AuthLogin
    @Operation(summary = "支付方式为微信支付时,创建小程序拉起微信接口所需参数map")
    @PostMapping("/wxPay/createJsapi/{paymentType}/{orderNo}")
    public Result<Map<String, String>> createJsapi(
            @PathVariable String paymentType,
            @PathVariable String orderNo) {
        Map<String, String> map = wxPayService.createJsapi(paymentType, orderNo);
        return Result.ok(map);
    }

    /**
     * 支付状态查询
     *
     * @param orderNo
     * @return
     */
    @AuthLogin
    @Operation(summary = "支付状态查询")
    @GetMapping("/wxPay/queryPayStatus/{orderNo}")
    public Result<Boolean> queryPayStatus(@PathVariable String orderNo) {
        Boolean status = wxPayService.queryPayStatus(orderNo);
        return Result.ok(status);
    }
}
